package com.google.gwt.livinglife.server.data;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Order;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Text;
import com.google.gwt.livinglife.client.data.LivingLifeGroupData;
import com.google.gwt.livinglife.client.data.UserIdData;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class LivingLifeGroup {
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private Long id;
  
	 @Persistent
	 private String name;
	 
	 @Persistent
	 private Text description;
	 
	 @Persistent
//	 @Order(extensions = @Extension(vendorName="datanucleus", key="list-ordering", value=" "))
	 private List<String> members = new ArrayList<String>();
	 
	 @Persistent
//	 @Order(extensions = @Extension(vendorName="datanucleus", key="list-ordering", value=" "))
	 private List<String> moderators = new ArrayList<String>();

	public LivingLifeGroup(LivingLifeGroupData data) {
		if (data.getId() != null) {
			id = data.getId();
		}
		name = data.getName();
		description = new Text(data.getDescription());
		members = new ArrayList<String>();
		Iterator<UserIdData> member_iterator = data.getMembers().iterator();
		while (member_iterator.hasNext()) {
			members.add(member_iterator.next().getId());
		}
		moderators = new ArrayList<String>();
		Iterator<UserIdData> moderator_iterator = data.getModerators().iterator();
		while(moderator_iterator.hasNext()) {
			moderators.add(moderator_iterator.next().getId());
		}
		data.getModerators();
	}
	public Long getId() {
		return id;
	}


	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Text getDescription() {
		return description;
	}

	public void setDescription(Text description) {
		this.description = description;
	}

	public List<String> getMembers() {
		return members;
	}

	public void setMembers(List<String> members) {
		this.members = members;
	}

	public List<String> getModerators() {
		return moderators;
	}

	public void setModerators(List<String> moderators) {
		this.moderators = moderators;
	}
}
